import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
  const count = ref(0)
  const doubleCount = computed(() => count.value * 2)
  function increment() {
    count.value++
  }

  return { count, doubleCount, increment }
})

export const useLoadStore = defineStore('loading', () => {
  const load = ref(0)
  function open () {
    load.value ++
  }
  function close () {
    load.value --
  }
  return { load, open, close }
})

export const RegisterStore = defineStore('register', () => {
  const register = ref({})
  function set (obj) {
    register.value = obj
  }
  function get () {
    return register
  }
  return { register, set, get }
  }, {
  persist: {
    storage: sessionStorage
  }
})

export const EmployeeStore = defineStore('employee', () => {
  const employee = ref({})
  function set (obj) {
    employee.value = obj
  }
  function get () {
    return employee
  }
  return { employee, set, get }
}, {
  persist: {
    storage: sessionStorage
  }
})
